/**  
 * All rights Reserved, Designed By Android_Robot   
 * @Title:  CommonWebView.java   
 * @Package com.jiyi.activity   
 * @Description:    TODO(用一句话描述该文件做什么)   
 * @author: HYM     
 * @date:   2017-6-1 下午3:03:44   
 * @version V1.0     
 */
package com.jiyi.activity;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebSettings.RenderPriority;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.swift.base.ApplicationBase;
import com.swift.maintenance.R;
import com.swift.maintenance.base.AppConfig;
import com.swift.maintenance.utils.UserInfoUtil;

/**
 * @ClassName: CommonWebView
 * @Description:TODO(这里用一句话描述这个类的作用)
 * @author: HYM
 * @date: 2017-6-1 下午3:03:44
 * 
 */
public class TrainFragment extends Fragment {
	private WebView mWebView;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_info, container, false);
		initView(view);
		return view;
	}

	private void initView(View view) {
		mWebView = (WebView) view.findViewById(R.id.info_webview);
		mWebView.requestFocusFromTouch();
		WebSettings webSettings = mWebView.getSettings();

		// 提高渲染优先级
		webSettings.setRenderPriority(RenderPriority.HIGH);

		// 设置可读取的文件
		webSettings.setAllowFileAccess(true);
		// 设置手机屏幕适适应
		webSettings.setUseWideViewPort(true);
		webSettings.setLoadWithOverviewMode(true);

		webSettings.setJavaScriptEnabled(true);
		webSettings.setSupportZoom(false);
		mWebView.setWebViewClient(new WebChromeClientApp());

		String account = ApplicationBase.LocalData.getString("input.user", "");
		String password = ApplicationBase.LocalData.getString("password", "");
		
		String url = AppConfig.TEXT_HOST + "/Train/Index/app_main/account/" + account + "/password/" + password+"/access_token/"+ UserInfoUtil.getCurrentUserAccessToken();

		mWebView.loadUrl(url);
	}

	private class WebChromeClientApp extends WebViewClient {
		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			view.loadUrl(url);
			return true;
		}

		@Override
		public void onPageStarted(WebView view, String url, Bitmap favicon) {

			super.onPageStarted(view, url, favicon);

		}

		@Override
		public void onPageFinished(WebView view, String url) {
			super.onPageFinished(view, url);
		}
	}

	
}
